﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jon.Adventureworks.Core.ExtensionMethods
{
    public static class StringBuilderExtensions
    {
        /// <summary>
        /// Trims a StringBuilders trailing comma.
        /// </summary>
        /// <param name="sb">The sbStringBuilder.</param>
        /// <returns>StringBuilder with any trailing commas trimmed.</returns>
        public static StringBuilder TrimSBTrailingComma(this StringBuilder sb)
        {
            if (sb == null) throw new ArgumentNullException("StringBuilder cannot be null when attempting to trim trailing commas.");

            if (sb.ToString().EndsWith(","))
            {
                // remove trailing comma.
                sb.Remove(sb.ToString().Length - 1, 1);
            }
            return sb;
        }
    }
}
